package com.bss.service.impl;

import com.bss.dao.CompanyMapper;
import com.bss.pojo.Company;
import com.bss.pojo.CompanyExample;
import com.bss.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 袁飞
 * @company 中原工学院
 * @create 2020-03-24-21:09
 */
@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    CompanyMapper companyMapper;
    public int addCompany(Company company) {
        return companyMapper.insert(company);
    }

    public int updateCompany(Company company) {
        return companyMapper.updateByPrimaryKeySelective(company);
    }

    public Company findCompanyById(Integer companyId) {
        return companyMapper.selectByPrimaryKey(companyId);
    }

    public int deleteCompanyById(Integer companyId) {
        return companyMapper.deleteByPrimaryKey(companyId);
    }

    public List<Company> findAll() {
        CompanyExample companyExample = new CompanyExample();
        CompanyExample.Criteria criteria = companyExample.createCriteria();
        return companyMapper.selectByExample(companyExample);
    }

    /**
     * 根据companyType查询company
     * @param companyType
     * @return
     */
    public List<Company> findCompanysByCompanyType(Integer companyType) {
        CompanyExample companyExample = new CompanyExample();
        CompanyExample.Criteria criteria = companyExample.createCriteria();
        criteria.andCompanyTypeEqualTo(companyType);
        return companyMapper.selectByExample(companyExample);
    }

    /**
     * 根据companyName和companyAddr进行模糊查询
     * @param companyName
     * @param companyAddr
     * @return
     */
    public List<Company> findCompany(String companyName, String companyAddr) {
        CompanyExample companyExample = new CompanyExample();
        CompanyExample.Criteria criteria = companyExample.createCriteria();
        criteria.andCompanyNameLike("%"+companyName+"%");
        criteria.andCompanyAddrLike("%"+companyAddr+"%");
        return companyMapper.selectByExample(companyExample);
    }
}
